package com.jarvis.du.lifecycle;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;

/**
 * Author: dyj
 * Date: 2019/4/11 16:54
 * E-mail: dyj@yitong.com.cn
 */
public class MyViewMode extends AndroidViewModel {
    Handler handler = new Handler(Looper.getMainLooper());

    private MutableLiveData<String> users;

    public MyViewMode(@NonNull Application application) {
        super(application);
    }


    public LiveData<String> getInfo() {
        if (users == null) {
            users = new MutableLiveData<String>();
        }

//        CountDownTimer timer = new CountDownTimer(999000, 500) {
//            @Override
//            public void onTick(long millisUntilFinished) {
//
//            }
//
//            @Override
//            public void onFinish() {
//                tv_skipTime.setText(String.format("%s s 跳过", 0));
//                splashJumpFinish = true;
////                    staac
//                startToMain();
//            }
//        };
//        splashViewTimer.start();

        handler.post(runnable);

        return users;
    }

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            users.setValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
            handler.postDelayed(runnable,500);
        }
    };

    public MyLiveData getWifi(){
        return MyLiveData.getInstance(getApplication());
    }
}
